<?php

namespace app\admin\model;

use think\Model;


class Post extends Model
{

    

    

    // 表名
    protected $name = 'post';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'media_type_text',
        'status_text'
    ];
    

    
    public function getMediaTypeList()
    {
        return ['image' => __('Media_type image'), 'video' => __('Media_type video')];
    }

    public function getStatusList()
    {
        return ['normal' => __('Status normal'), 'hidden' => __('Status hidden')];
    }


    public function getMediaTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['media_type'] ?? '');
        $list = $this->getMediaTypeList();
        return $list[$value] ?? '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }




}
